public class Solution {
    char[] arr;
    private void reverse(int l, int r){
        while(l < r){
            char tmp = arr[l];
            arr[l] = arr[r];
            arr[r] = tmp;
            l++;
            r--;
        }
    }
    public String reverseStr(String s, int k) {
        int n = s.length();
        arr = s.toCharArray();
        int i;
        for(i = 0; i < n; i += (2 * k)){
             int l  = i;
            //判断尾数够不够k个字符
            int r = Math.min(n - 1, l + k - 1);
            reverse(l, r);
        }

        return new String(arr);
    }

}
